<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY iso "http://xmlns.heustics.org/schema/iso/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xf="http://www.w3.org/2002/xforms"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="&a;"
  xmlns:o="&a;Document#"  
  xmlns:dt="&a;dates#"
  exclude-result-prefixes="xsl xf l dt a o"
>  
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;Document#node-editor-common')"/>    
  <xsl:variable name="o:params-l10n" select="$o:l10n/l:context[@name='params']/*"/>
  <xsl:variable name="o:hints-l10n" select="$o:l10n/l:context[@name='param-hints']/*"/>  
    
  <xsl:template match="a:form[@mode='preview']"> 
    <xsl:param name="account" select="/*/a:account"/>
    <xsl:variable name="model" select="xf:model[1]"/>
    <xsl:variable name="subm" select="$model/xf:submission[1]"/>
    <div class="node_request_form preview">      
      <form class='preview-form' method='{$subm/@method}' action='{a:format-repeat-request($subm/@action)}'> 
        <input type='hidden' name='http-post-encoding' value='iso-8859-1'/>
        <input type='hidden' name='stage' value='{a:submission[1]/@stage}'/>  
        <input type='hidden' name='target' value='{@target}'/> 
        <input type='hidden' name='target-action' value='{@target-action}'/>
        <xsl:if test="$account/@token">
          <input type='hidden' name='token' value='{$account/@token}'/>
        </xsl:if>     
        <xsl:apply-templates select="$model/xf:instance[1]/*" mode="a:preview-instance"/>
        <div class="submits">
          <xsl:apply-templates select="a:submission[1]"/>
          <div class="spacer"/>
        </div>        
      </form>
    </div>
  </xsl:template>  
  
  <xsl:template match="a:*[@node-id or @target-id]" mode="a:preview-instance">
    <xsl:apply-templates mode="a:input-hidden"/>
  </xsl:template> 
  
  <xsl:template match="a:keywords|a:order-key" mode="a:input-show">
    <xsl:param name="key" select="local-name()"/> 
    <xsl:call-template name="a:simple-input-show">
      <xsl:with-param name="key" select="$key"/>
      <xsl:with-param name="label" select="$o:params-l10n[@key=$key]"/>
      <xsl:with-param name="hint" select="$o:hints-l10n[@key=$key]"/>
    </xsl:call-template>
  </xsl:template>
     
  <!-- fields that are read only --> 
  <xsl:template match="a:type|a:language|a:region|a:base-uri|a:data-uri|a:parents|a:contains" mode="a:input-hidden"/>  
  <xsl:template match="a:type|a:base-uri|a:data-uri|a:parents|a:contains" mode="a:input-show"/>
  
  <xsl:template match="a:node-grouping" mode="a:input-hidden">
    <input name="node-grouping" type="hidden" value="{@selected}"/>  
  </xsl:template>
  
  <xsl:template match="a:title" mode="a:input-show" name="a:input-show-title">
    <div class='input text title'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='title']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='title']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <span><xsl:value-of select="."/></span>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
    <!-- xsl:apply-templates select="." mode="a:input-methods">
      <xsl:with-param name="methods" select="$a:head/a:methods/*"/>
    </xsl:apply-templates -->
  </xsl:template>
  
  <xsl:template match="a:node-grouping" mode="a:input-show">    
    <xsl:param name="key" select="'grouping'"/>
    <div class='input text {$key}'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <xsl:value-of select="$o:params-l10n[@key=$key]"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key=$key]"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>    
        <div class="entry">
          <xsl:variable name="opts" select="a:options"/>
          <xsl:choose>
            <xsl:when test="$opts/@count &gt; 1">
              <select name="node-grouping">          
                <xsl:apply-templates select="$opts/*" mode="a:single-select-label">
                  <xsl:with-param name="selected" select="@selected"/>     
                </xsl:apply-templates>
              </select>    
            </xsl:when>
            <xsl:when test="$opts/@count = 1 and $opts/*[1]/@label">
              <span>
                <xsl:value-of select="$opts/*[1]/@label"/>
              </span>
            </xsl:when>
            <xsl:otherwise>
              <span>
                <xsl:value-of select="$o:l10n/l:gentext[@key='no-grouping']"/>
              </span>
            </xsl:otherwise>
          </xsl:choose>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>   
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:title" mode="a:input-show">
    <div class='input text title'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='title']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='title']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <input class='large' type="text" value="{.}" name="title"/>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:keywords" mode="a:input-show">        
    <div class='input text keywords'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='keywords']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='keywords']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <input class='max' type="text" value="{.}" name="keywords"/>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template> 
  
  <xsl:template match="a:description" mode="a:input-show">
    <div class='input textarea description'>      
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='description']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='description']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <textarea class="max" name="description">
            <xsl:value-of select="."/>
          </textarea>
          <div class="spacer"/>
        </div>       
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:body" mode="a:input-show">    
    <div class='input textarea body'>      
      <div class='key'>
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='body']"/></span>
          <div class="spacer"/>
        </div>
        <div class='hint body'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='body']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <div class="entry">
          <textarea class="max" name="body">
            <xsl:value-of select="."/>
          </textarea>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template> 
    
  <xsl:template match="a:language|a:region" mode="a:input-show">
    <xsl:variable name="key" select="local-name()"/>
    <div class='input text {$key}'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key=$key]"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key=$key]"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>        
        <div class="entry">
          <xsl:variable name="sel" select="@selected"/>
          <span><xsl:value-of select="a:get-l10n(concat('&iso;',$key))/l:context[@name='names']/*[@key=$sel]"/></span>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>   
  
  <xsl:template match="a:ordering" mode="a:input-hidden">
    <input type="hidden" name="order-by" value="{a:method/@selected}"/>
    <input type="hidden" name="order-direction" value="{a:direction/@selected}"/>
  </xsl:template>
  
  <xsl:template match="a:ordering" mode="a:input-show" name="a:ordering-input-show">
    <xsl:param name="order-by-l10n" select="$o:l10n/l:context[@name='order-by-options']/*"/>
    <xsl:param name="order-direction-l10n" select="$o:l10n/l:context[@name='order-direction-options']/*"/>
    <xsl:param name="label" select="$o:params-l10n[@key='ordering']"/>
    <xsl:param name="hint" select="$o:hints-l10n[@key='ordering']"/>   
    <div class="input select order">
      <div class="key">
        <div>
          <xsl:choose>
            <xsl:when test="a:method/@error or a:direction/@error">
              <xsl:call-template name="a:label-class-attr">
                <xsl:with-param name="error" select="1"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="a:label-class-attr"/>
            </xsl:otherwise>
          </xsl:choose>          
          <span><xsl:value-of select="$label"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='ordering']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>  
      <div class="value">
        <div class="entry value_item order_by">
          <div class="value_item_title">
            <span><xsl:value-of select="$o:params-l10n[@key='order-by']"/></span>
            <div class="spacer"/> 
          </div>
          <div class="value_item_value">
            <select name="order-by">
              <xsl:variable name="n" select="a:method/@selected"/>
              <xsl:for-each select="$order-by-l10n">
                <option value="{@key}">
                  <xsl:if test="$n = @key">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="."/>
                </option>
              </xsl:for-each>
            </select> 
            <div class="spacer"/>    
          </div>         
          <div class="spacer"/>    
        </div>
        <div class="entry value_item order_direction">
          <div class="value_item_title">
            <span>
              <xsl:value-of select="$o:params-l10n[@key='order-direction']"/>
            </span>
            <div class="spacer"/>
          </div>
          <div class="value_item_value">
            <select name="order-direction">
              <xsl:variable name="n" select="a:direction/@selected"/>
              <xsl:for-each select="$order-direction-l10n">
                <xsl:variable name="p" select="@key"/>
                <option value="{@key}">
                  <xsl:if test="$n = @key">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="."/>
                </option>
              </xsl:for-each>
            </select> 
            <div class="spacer"/>       
          </div>         
          <div class="spacer"/>
        </div>       
        <div class="spacer"/>
      </div>    
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:publishDates" mode="a:input-hidden">
    <xsl:apply-templates mode="dt:input-hidden"/>
  </xsl:template>
  
  <xsl:template match="s" mode="dt:parts-input-hidden"/>
  <xsl:template match="s" mode="dt:parts-input"/>
  
  <xsl:template match="a:publishDates" mode="a:input-show">
    <xsl:param name="config"/>
    <xsl:apply-templates mode="a:publishDates-input-show">
      <xsl:with-param name="config" select="$config"/>
    </xsl:apply-templates>
  </xsl:template>
   
  <xsl:template match="a:effectiveDate|a:expiryDate" mode="a:publishDates-input-show">    
    <xsl:param name="key" select="local-name()"/>
    <xsl:param name="config" select="/*/a:config"/>
    <div class='input text {$key}'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key=$key]"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key=$key]"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <xsl:call-template name="dt:input">
          <xsl:with-param name="name" select="$key"/>
          <xsl:with-param name="config" select="$config"/>
        </xsl:call-template>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
  </xsl:template>
  
</xsl:stylesheet>
